package com.tester.zc.test002.thread;

import java.util.Random;

/**
 * 线程二
 *
 * @Author zhoucan
 * @Date 2022/12/11
 */
public class ThreadTwo extends Thread {

    /**
     * 最小值
     */
    private int min= 0;
    /**
     * 最大值
     */
    private int max= 10;

    public void run() {
        while(true) {
            try{
                //睡眠
                Thread.sleep(1000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            Random ran = new Random();
            //当前猜的数字
            int input = min + ran.nextInt(max - min);
            switch (ThreadOne.checkNum(input)) {
                case "1":
                    min = input;
                    System.out.println("我猜的数字是：" + input);
                    System.out.println("猜小了");
                    break;
                case "2":
                    max = input;
                    System.out.println("我猜的数字是：" + input);
                    System.out.println("猜大了");
                    break;
                default:
                    System.out.println("我猜的数字是：" + input);
                    System.out.println("猜对了");
                    System.exit(0);
            }
        }
    }
}
